package com.deer.wms.inventory.web;

import com.deer.wms.inventory.model.freeze.FreezeDetail;
import com.deer.wms.inventory.model.freeze.FreezeDetailCriteria;
import com.deer.wms.inventory.model.freeze.FreezeDetailDto;
import com.deer.wms.inventory.service.FreezeDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2019/12/25.
*/
@Api(description = "冻结Detail api接口")
@RestController
@RequestMapping("/freeze/details")
public class FreezeDetailController {

    @Autowired
    private FreezeDetailService freezeDetailService;

    @PostMapping("/insert")
    public Result add(@RequestBody FreezeDetail freezeDetail) {
        freezeDetailService.save(freezeDetail);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        freezeDetailService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody FreezeDetail freezeDetail) {
        freezeDetailService.updateById(freezeDetail);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(Integer id) {
        FreezeDetail freezeDetail = freezeDetailService.getById(id);
        return ResultGenerator.genSuccessResult(freezeDetail);
    }

    @GetMapping("/list")
    public Result list(FreezeDetailCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<FreezeDetailDto> list = freezeDetailService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
